﻿using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;

public enum EColor
{
    All,
    Blue,
    Green,
}

[RequireComponent(typeof(CTilemap))]
//可互动平台的父类
public class Platform_Collide : MonoBehaviour
{
    protected EventSystem eventSystem;
    protected CTilemap cTilemap;
    protected CTileMap_Canvas canvas;           //生成动画效果的画布
    protected List<Vector3Int> tilePositions;   //所有tile的坐标
    protected List<TileBase> tiles;             //所有tile

    public EColor targetColor;
    [SerializeField]
    protected bool _Active; //是否激活
    public bool Active
    {
        get => _Active;
        set
        {
            if (_Active == value)
                return;
            _Active = value;
            OnActivate(value);
        }
    }

    protected void Awake()
    {
        eventSystem = Service.Get<EventSystem>();
        cTilemap = GetComponent<CTilemap>();

        GameObject obj = Instantiate(transform.parent.GetComponentInChildren<CTileMap_Canvas>().gameObject);
        obj.transform.SetParent(transform);
        canvas = obj.GetComponent<CTileMap_Canvas>();
    }

    protected void Start()
    {
        tilePositions = cTilemap.GetAllPosition();
        tiles = cTilemap.GetAll();
        if (tiles.Count == 0)
            Destroy(this);
        OnStart();
    }

    protected virtual void OnEnable()
    {
        eventSystem.CollidePlatform += OnPlayerCollide;
    }
    protected virtual void OnDisable()
    {
        eventSystem.CollidePlatform -= OnPlayerCollide;
    }
    protected virtual void OnStart() { }
    protected virtual void OnPlayerCollide(Vector2 normalLine,GameObject platform,Character player){ }
    protected virtual void OnActivate(bool active) { }
}
